import main from '../../../main';
import { download } from '../../../api';
import { clearEmptyKey } from '../../../utils/utils';

// 根据卡ID获取可充值列表
export async function apiGetCardPackDetailListByCardId(pageNum: number, pageSize: number, params?: any) {
    let tParams = params ? clearEmptyKey(params) : null;
    let res = await main.api.get('/card/cardPackDetail/listByCardId', {
        params: { pageNum, pageSize, ...tParams, status: 'N' },
    });

    return res;
}
// 购买通用套餐包
export async function apiGetCardPackDetailListByCard(pageNum: number, pageSize: number, params?: any) {
    let tParams = params ? clearEmptyKey(params) : null;
    let res = await main.api.get('/card/cardPackDetail/list', {
        params: { pageNum, pageSize, ...tParams, status: 'enable' },
    });

    return res;
}
// 购买套餐
export async function apiBuyPackOrder(data: any) {
    let res = await main.api.post('/card/cardPackOrder/buy', data);
    return res;
}
// 购买套餐预览
export async function apiPreOrder(
    cardPackDetailId: string | number,
    cardId: string | number,
    couponCodeIds?: Array<number>,
    number?: number
) {
    let res = await main.api.post('/card/cardPackOrder/preview', {
        cardPackDetailId,
        cardId,
        couponCodeIds,
        number: number ?? 1,
    });
    return res;
}
//买套餐--查询可用券列表
export async function apiGetCouponListByCardPackDetailId(cardId: number, cardPackDetailId: number, number?: number) {
    let res = await main.api.get('/card/cardPackOrder/getCouponListByCardPackDetailId', {
        params: {
            cardId,
            cardPackDetailId,
            number: number ?? 1,
        },
    });

    return res;
}
// 升级套餐预览 changeType 1升级流量 2延长期限
export async function apiPreUpdatePack(cardId: string | number, changeType: string, packDetailId?: string) {
    return main.api.get('/card/cardPackOrder/changePackPreview', { params: { cardId, changeType, packDetailId } });
}

// 升级套餐
export async function apiUpdatePack(cardId: string | number, changeType: string, packDetailId?: string) {
    return main.api.get('/card/cardPackOrder/changePackOrder', { params: { cardId, changeType, packDetailId } });
}